home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1025 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.8 KB  |  93 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: "I\qaky P\irez Gonz\alez" <inaky@eneline.es>
  3. Newsgroups: comp.std.c++
  4. Subject: Is typeof legal under ANSI C++?
  5. Date: 10 Apr 1996 14:56:38 GMT
  6. Organization: ?
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4kgi76$qf1@engnews1.Eng.Sun.COM>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset="us-ascii"
  12. X-Nntp-Posting-Host: 194.224.7.5
  13. X-Lines: 79
  14. Content-Length: 2008
  15. Originator: clamage@taumet
  16.  
  17.  
  18.     Hi!!
  19.  
  20.     I'm facing a BIG problem, developing under GCC/2.7.2 and the only
  21. sollution I've found is using the "typeof()" keyword, but I'm afraid of
  22. losing compatibility and those things ...
  23.  
  24.     So, my cuestion is that of the subject. Does typeof() conform to
  25. ANSI C++?
  26.  
  27.     The problem is the following: I have a templated class, named A,
  28. which may be applied the array operator. Then I have another templated
  29. class, name it B which is an smart pointer to classes of any type (in
  30. fact, this is used for classes which have a resource count which
  31. has to be kept updated ... more or less like the Fresco toolkit and a
  32. lot more I don't know of :).
  33.  
  34.     Well, the idea is that when "working daily" with objects of class
  35. A, they'll be pointers, and when storing the pointers into smart pointers,
  36. you have to dereference it and then apply the operator array, like
  37. (*b)[4], which is kind of ugly. This is not too important, but when you
  38. are refering to nested arrays of smart pointers, it keeps going uglier
  39. (for example (*(*(*b)[3])[1])[4] for a three-level nested array).
  40.  
  41.     So, if I manage to make a method in the smart pointer which passes
  42. the array operator to the item it points to and returns a reference to the
  43. object it returns, I am done. Here is where the typeof() keyword appears.
  44. If not, I don't know which type to return in the array operator of the
  45. smart pointer.
  46.  
  47.     Here is the simplified code explaining the example ...
  48.  
  49. template<class T>
  50. class A
  51. {
  52. public:
  53.     virtual T& operator [] (unsigned int i) {return 3; };
  54. };
  55.  
  56. template<class T>
  57. class B
  58. {
  59. public:
  60.     virtual typeof((*a)[0]) operator[] (unsigned int a)
  61.     {
  62.         return (*a)[i];
  63.     };
  64.     virtual operator T* () const
  65.     {
  66.         return a;
  67.     }
  68.     T* a;
  69. };
  70.  
  71. int main (void)
  72. {
  73.     A<int>        df;
  74.     B<A<int> >    tf;
  75.  
  76.     return tf[2];
  77. }
  78.  
  79.     Well, this is all folks :) TIA
  80.  
  81. --Inaky Perez Gonzalez <inaky@peloncho.fis.ucm.es> <2:341/5.31@fidonet.org> --
  82. --- PGP Key fingerprint = 8E 34 3A 62 64 99 E2 44  AD 7B 30 D9 DD FF 3E 4C ---
  83.          (PGP public key available via finger/e-mail request)
  84.  
  85.  
  86.  
  87.  
  88. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  89. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  90. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  91. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  92. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  93.